@extends('admin.layout')
@section('body')
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <table id="adminTable" lay-filter="adminTable"></table>
            </div>
        </div>
    </div>
@stop
@push('script')
    <script type="text/html" id="allocationTpl">
        <div style="padding: 20px;">
            <div class="layui-form-item">
                <label class="layui-form-label">话务:</label>
                <div class="layui-input-block">
                    <x-system.user id="txtCallerId" show-all="--选择话务员--"
                                   group="{{\App\Models\System\Group::CALLER}}"></x-system.user>
                </div>
            </div>
        </div>
    </script>
    <script type="text/javascript">
        layui.use(['layer', 'form', 'table', 'util', 'admin'], function () {
            //加载完成
            var listTableInc = new ListTable("{{admin_url($baseRoute.'pager')}}");
            @auth('receive')
            listTableInc.confirmBar('<button type="button" class="layui-btn layui-btn-xs">领取</button>', '确认要领取吗？', (tb, d) => {
                return SystemUtil.ajax("{{admin_url($baseRoute.'receive')}}").setData({id: d.id});
            });
            @endauth
            @auth('allocation')
            listTableInc.topAction('<button type="button" class="layui-btn layui-btn-normal layui-btn-xs"  title="分配">分配</button>', function (layero, index) {
                let checkStatus = layui.table.checkStatus('adminTable')
                    , data = checkStatus.data, ids = [];
                data.forEach(function (item) {
                    ids.push(item.id);
                });
                if (ids.length == 0) {
                    layer.msg('请选择要分配的记录');
                    return false;
                }
                layer.open({
                    type: 1,
                    title: '分配',
                    btn: ['分配', '取消'],
                    area: ['400px', '160px'],
                    content: allocationTpl.innerHTML,
                    success: function (layero, index) {
                        SystemUtil.popViewSet(index);
                        layui.form.render('select');
                    },
                    yes: function (index, layero) {
                        let caller_id = layui.$(layero).find('#txtCallerId').val();
                        if (!caller_id) {
                            layer.msg('请选择话务员');
                            return;
                        }
                        let loadIndex = layer.load(3);
                        SystemUtil.ajax("{{admin_url($baseRoute.'allocation')}}", 'POST').setData({
                            ids: ids.join(','),
                            caller_id
                        }).send(3).then(res => {
                            location.reload();
                        }).always(function () {
                            layer.close(loadIndex);
                            layer.close(index);
                        });
                    }
                });
            });
            @endauth
            listTableInc.checkbox();
            listTableInc.lineNumber();
            listTableInc.column("预约号", "id").setWidth(100);
            listTableInc.column("姓名", "name");
            listTableInc.column("手机号", "mobile");
            listTableInc.column("性别", "gender_text").setWidth(60);
            listTableInc.column("年龄", "age").setWidth(60);
            listTableInc.column("相关病种", "diseases");
            listTableInc.column("区域", "area_name");
            listTableInc.column("咨询员", "custom_service_name");
            listTableInc.column("登记时间", "created_at").setWithDateTime();
            listTableInc.rowBarWidth = 70;
            listTableInc.render();
        });
    </script>
@endpush
